import 'package:boss/textStyle/text_style.dart';
import 'package:boss/ui/page/miniProgram/miniProgramCommodityConfig/mini_program_commodity_config_page.dart';
import 'package:boss/ui/page/miniProgram/miniProgramConfig/mini_program_config_page.dart';
import 'package:boss/ui/page/miniProgram/miniProgramConfigPreview/mini_program_config_preview_page.dart';
import 'package:boss/ui/page/miniProgram/miniProgramMemberConfig/mini_program_member_config_page.dart';
import 'package:boss/ui/page/miniProgram/miniProgramMode/mini_program_mode_page.dart';
import 'package:boss/ui/page/modulePage/model/module_data.dart';
import 'package:boss/ui/page/modulePage/widget/module_grid.dart';
import 'package:boss/ui/widget/alert/alert.dart';
import 'package:boss/ui/widget/center_title_app_bar.dart';
import 'package:boss/ui/widget/image/base_image.dart';
import 'package:boss/ui/widget/label_button.dart';
import 'package:flutter/material.dart';
import 'package:router/annotation.dart';
import 'package:hi_common/hi_common.dart';

@RouterConfig(MiniProgramIndexPage.pageName)
class MiniProgramIndexPage extends StatefulWidget {
  static const pageName = '/MiniProgramIndexPage';

  @override
  _MiniProgramIndexPageState createState() => _MiniProgramIndexPageState();
}

class _MiniProgramIndexPageState extends BaseState<MiniProgramIndexPage> {
  _MiniProgramIndexPageState() : super(MiniProgramIndexPage.pageName);

  final List<ModuleData> data = [
    ModuleData(title: '点餐', data: [
      Module(title: '点餐模式', icon: 'assets/image/miniProgram/order_mode_icon.png', url: MiniProgramModePage.pageName),
      Module(title: '点餐二维码', icon: 'assets/image/miniProgram/qrcode_icon.png', url: MiniProgramConfigPage.pageName),
    ]),
    ModuleData(title: '菜品', data: [
      Module(title: '菜品设置', icon: 'assets/image/miniProgram/commodity_icon.png', url: MiniProgramCommodityConfigPage.pageName),
    ]),
    ModuleData(title: '会员', data: [
      Module(title: '会员设置', icon: 'assets/image/miniProgram/member_icon.png', url: MiniProgramMemberConfigPage.pageName),
    ]),
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: CenterTitleAppBar(title: '扫码点餐'),
      body: SingleChildScrollView(
        padding: EdgeInsets.symmetric(horizontal: 30.w),
        child: Column(
          children: [
            buildHeader(),
            ...buildContent(),
          ],
        ),
      ),
    );
  }

  Widget buildHeader() {
    return Column(
      children: [
        Container(
          height: 90.w,
          alignment: Alignment.centerLeft,
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Text('扫码点餐', style: TextStyleConstant().normal_1_44.copyWith(fontWeight: FontWeight.bold)),
              GestureDetector(
                onTap: () {
                  showAlert(
                    context,
                    title: '未开启',
                    content: '您还未完成相关设置，无法\n开启扫码点餐',
                    confirmText: '启 用',
                    onConfirm: (context) {
                    }
                  );
                },
                child: Row(
                  children: [
                    Text('未开启', style: TextStyleConstant().origin_24),
                    Container(
                      margin: EdgeInsets.only(left: 10.w),
                      child: BaseImage(
                        'assets/image/arrow_right_icon.png',
                        width: 12.w,
                        height: 20.w,
                      ),
                    ),
                  ],
                ),
              ),
            ],
          ),
        ),
        Container(
          height: 50.w,
          decoration: BoxDecoration(
            color: const Color(0xFFFF564C).withOpacity(0.1),
            borderRadius: BorderRadius.circular(25.w),
          ),
          child: Row(
            children: [
              Container(
                child: BaseImage(
                  'assets/image/miniProgram/error_tip.png',
                  width: 26.w,
                  height: 26.w,
                ),
                margin: EdgeInsets.symmetric(horizontal: 10.w),
              ),
              Text(
                '您还未完成相关设置，无法开启扫码点餐',
                style: TextStyle(
                  fontSize: 22.sp,
                  color: const Color(0xFFFF564C),
                ),
              ),
              Spacer(),
              LabelButton(
                title: '继续完成',
                textStyle: TextStyleConstant().blue_24,
                padding: EdgeInsets.symmetric(horizontal: 20.w, vertical: 4),
                onTap: () {
                  Navigator.pushNamed(context, MiniProgramConfigPreviewPage.pageName);
                },
              ),
            ],
          ),
        ),
      ],
    );
  }

  List<Widget> buildContent() {
    return data
        .map((item) => ModuleGrid(
              item,
              iconSize: 70.w,
              onItemTap: (data) {
                Navigator.pushNamed(context, data.url);
              },
            ))
        .toList();
  }
}
